package obstaculos;

import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.TextureManager;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import android.content.Context;

public class Elevador extends Obstaculo{

	private BitmapTextureAtlas mapaDeTexturas;
	private TextureRegion textura;
	public float vely = 0;
	
	public Elevador(int x, int y, Context contexto, TextureManager tm) {
		
		this.x = x;
		this.y = y;
		yInicial = y;
		largura = 192;
		altura = 64;
		
		mapaDeTexturas = new BitmapTextureAtlas(256, 64, TextureOptions.BILINEAR);
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/obstaculos/");
		textura = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mapaDeTexturas, contexto, "Elevador.png", 0, 0);
		tm.loadTexture(mapaDeTexturas);
		
		sprite = new Sprite(x, y, textura);
	}

	@Override
	public void atualiza() {
		if(meuGatilho.ativado){
			if(y > altura * 2){
				y-=4;
			}
		}
		if(!meuGatilho.ativado && y < yInicial){
			y+=4;
		}
	}

	@Override
	public boolean colidiuComDono(AnimatedSprite spriteDono) {
		if(spriteDono.collidesWith(sprite)){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public void posicionaNaCena (int mapx,int mapy) {
		sprite.setPosition((int)x-mapx, (int)y-mapy);
	}
}
